﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;

namespace XiaoYuStock.Core
{
   public class JsonHelper
    {
        public static string ToJson(object obj)
        {
            var serializer = new JavaScriptSerializer();
            var json = serializer.Serialize(obj);
            return json;
        }

        public static T FromJson<T>(string json)
        {
            var serializer = new JavaScriptSerializer();
            var obj = serializer.Deserialize<T>(json);
            return obj;
        }
        /// <summary>
        /// 作者：Ark
        /// 时间：2014-08-18
        /// 描述：反序列化Json数据
        /// </summary>
        /// <param name="json">Json数据</param>
        /// <param name="type">类型</param>
        /// <returns></returns>
        public static object FromJson(string json, Type type)
        {
            var serializer = new JavaScriptSerializer();
            var obj = serializer.Deserialize(json, type);
            return obj;
        }
    }
}
